/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 */
var getIntersectionNode = function(headA, headB) {
    if(headA===null||headB===null){
        return null
    }
   const b= new Set()
    let temp=headA
    while(temp!==null)
    {
        b.add(temp)
        temp=temp.next
    }
    temp=headB 
    while(temp!==null){
        if(b.has(temp))
        {
            return temp
        }
        temp=temp.next
    }
    return null
  
};